import { demandList } from '../services/api';

export default {
  namespace: 'buyIntention',

  state: {
    data: {
      list: [],
      pagination: {},
      detail: {
        tradeOrder: {},
        buyerProfile: {},
      },
    },
  },

  effects: {
    *queryList({ payload }, { call, put }) {
      const response = yield call(demandList, payload);

      let data = {
        list: response.data.list,
        pagination: {
          total: response.data.total,
          pageSize: response.data.pageSize,
          current: parseInt(payload.pageNum, 10) || 1,
        },
      };

      yield put({
        type: 'setList',
        payload: data,
      });
    },
  },

  reducers: {
    setList(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
  },
};
